package com.bruce.starts.demo.commonerror.transaction.demo;

import org.springframework.transaction.TransactionStatus;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 批量事务
 */
public class BatchTransactionInfo {
    private final AtomicInteger completeThreads = new AtomicInteger();
    private final AtomicInteger successThreads = new AtomicInteger();
    private final int groupSize;
    private boolean batchTransaction;
    //线程事务map
    private Map<Long, TransactionStatus> longTransactionStatusMap;

    public BatchTransactionInfo(int groupSize, boolean batchTransaction) {
        this.groupSize = groupSize;
        this.batchTransaction = batchTransaction;
        if (batchTransaction) {
            longTransactionStatusMap = new ConcurrentHashMap<>();
        }
    }

    public AtomicInteger getCompleteThreads() {
        return completeThreads;
    }

    public AtomicInteger getSuccessThreads() {
        return successThreads;
    }

    public int getGroupSize() {
        return groupSize;
    }

    public boolean isBatchTransaction() {
        return batchTransaction;
    }

    public Map<Long, TransactionStatus> getLongTransactionStatusMap() {
        return longTransactionStatusMap;
    }
}
